coos.extend(String.prototype,{
	trim : function () 
	{
	    return this.replace(/(^\s*)|(\s*$)/g, "");
	},
	ltrim : function () 
	{
	    return this.replace(/^\s*/g, "");
	},
	rtrim : function ()
	{
	    return this.replace(/\s*$/g, "");
	},
	Trim : function() 
	{ 
	    return this.replace(/(^\s*)|(\s*$)/g, ""); 
	},
	LTrim : function() 
	{ 
	    return this.replace(/(^\s*)/g, ""); 
	},
	Rtrim : function() 
	{ 
	    return this.replace(/(\s*$)/g, ""); 
	},
	contains : function (string, s) 
	{
	    return (s) ? (s + this + s).indexOf(s + string + s) > -1 : this.indexOf(string) > -1;
	},
	equals : function () 
	{
	    for (var i = 0; i < arguments.length; i++) 
		{
	        if (this == arguments[i])
	            return true;
	    }
	    return false;
	},
	startsWith : function (A) 
	{
	    return (this.substr(0, A.length) == A);
	},
	endsWith : function (A, B) 
	{
	    var C = this.length;
	    var D = A.length;
	    if (D > C) 
		{
	        return false;
	    }
	    if (B) 
		{
	        var E = new RegExp(A + "$", "i");
	        return E.test(this);
	    } 
		else
		{
	        return (D == 0 || this.substr(C - D, D) == A);
	    }
	},
	remove : function (A, B)
	{
	    var s = "";
	    if (A > 0) {
	        s = this.substring(0, A);
	    }
	    if (A + B < this.length)
		{
	        s += this.substring(A + B, this.length);
	    }
	    return s;
	},
	replaceNewLineChars : function (A) 
	{
	    return this.replace(/\n/g, A);
	},
	escape : function () 
	{
		return this.replace(/('|\\)/g, "\\$1");
	},
	/**
	 * 字符串截取
	 */
	intercept : function(len)
	{
		if(this.length*2 <= len)
			return this;
		var strlen = 0; 
		var s = "";
		for(var i = 0; i < this.length; i++)
		{
			if(this.charCodeAt(i) > 128)
			{			
				strlen = strlen + 2;
				if(strlen > len)
					return s.substring(0,s.length-1) + "...";
			}
			else
			{
				strlen = strlen + 1;
				if(strlen > len)
					return s.substring(0,s.length-2) + "...";
			}
			s = s + this.charAt(i);
		}
		return s;
	},
	/**
	 * 字符串加法
	 * abc.times(3)=abcabcabc
	 */
	times : function(n)
	{
		var s = this;
		var total = "";
		while(n >0)
		{
			if(n%2 == 1)
			{
				total += s;
			}
			if(n == 1)
			{
				break;
			}
			s += s;
			n = n >> 1;
		}
		return total;
	},
	/**
	 * 批量替换字符
	 * var str = "<div>d&dkkd</div>";
	 * str = str.multiReplace({'&(?!#?\\w+;)' :'&amp;','"([^"]*)" : '“$1”','<' : '&lt;' ,'>' : '&gt;'})
	 */
	multiReplace : function(hash)
	{
		var str = this;
		for(var key in hash)
		{
			if(Object.prototype.hasOwnProperty.call(hash,key))
			{
				str = str.rplace(new RegExp(key,"g"),hash[key]);
			}
		}
		return str;
	},
	getFileType : function()
	{
		return this.substring(this.lastIndexOf(".")+1,this.length).toLowerCase();
	},
	toInt : function()
	{
		return parseInt(this, 10);
	},
	toFloat : function()
	{
		return parseFloat(this);
	},
	toArray : function(sp)
	{
		if(sp)
		{
			return this.trim().split(sp);
		}
		var arr = new Array();
		for(var i = 0; i < this.length; i++)
		{
			arr[i] = this.substr(i,1);
		}
		return arr;
	},
	random : function()
	{
		var arr = this.toArray();
		return arr[Math.floor(Math.random() * arr.length)] || null;
	},
	clean : function()
	{
		return this.replace(/\s{2,}/g, ' ').trim();
	},
	toJson : function()
	{
		if(this==""){
			return eval('({})');
		}
		return eval('(' + this + ')');
	}
});


function StringBuffer()
{
	var arr = new Array;
	return{
		append : function(str)
		{
			arr[arr.length] = str;  
		},
		toString : function()
		{
			return arr.join(""); 
		}
	}
}
